package ts;

import Dao.Impl.CarDAOImpl;
import org.junit.Test;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.util.Properties;
import java.util.Set;

public class demo1 {
    @Test
    public void test1() throws Exception {
        Properties properties = new Properties();
        System.out.println(properties);

        properties.load(new FileInputStream("src/main/resources/db.properties"));
        System.out.println(properties);

        String driver = properties.getProperty("driver");
        String url = properties.getProperty("url");
        String username = properties.getProperty("username");
        String password = properties.getProperty("password");

        System.out.println(driver);
        System.out.println(url);
        System.out.println(username);
        System.out.println(password);

        Set<String> keys = properties.stringPropertyNames();
        for(String key:keys){
            System.out.println(key+"="+properties.getProperty(key));
        }
    }

    @Test
    public void  test2() throws Exception {
        // 1、创建Properties对象出来，先用它存储一些键值对数据
        Properties properties = new Properties();
        properties.setProperty("张无忌", "minmin");
        properties.setProperty("殷素素", "cuishan");
        properties.setProperty("张翠山", "susu");

        // 2、把properties对象中的键值对数据存入到属性文件中去
        properties.store(new FileWriter("src/main/resources/db.properties")
                , "i saved many users!");
    }
    @Test
    public  void  test3() throws Exception {
        CarDAOImpl carDAO = new CarDAOImpl();
        System.out.println(carDAO.getAllCars());
    }
}
